package demo.common.config;

import demo.common.constants.Constant;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    @Bean(name = Constant.QUEUE_NAME)
    public Queue queue() {
        return QueueBuilder.durable(Constant.QUEUE_NAME).build();
    }

    @Bean(name = Constant.EXCHANGE_NAME)
    public FanoutExchange exchange() {
        return ExchangeBuilder.fanoutExchange(Constant.EXCHANGE_NAME).durable(true).build();
    }

    @Bean
    public Binding routing(@Qualifier(Constant.QUEUE_NAME) Queue queue,
                           @Qualifier(Constant.EXCHANGE_NAME) FanoutExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange);
    }
}
